# vhdl files
FILES = src/*
VHDLEX = .vhd

# testbench
TESTBENCHPATH = testbench/${TESTBENCH}$(VHDLEX)
TESTBENCHES = testbench/*

# GHDL CONFIG
GHDL_CMD = ghdl
GHDL_FLAGS = 

SIMDIR = simulation
# simulation break condition
# GHDL_SIM_OPT = --assert-level=error
GHDL_SIM_OPT = --stop-time=50000ns

WAVEFORM_VIEWER = gtkwave

all: compile run view

new:
	echo "Setting up project ${PROJECT}"
	mkdir src testbench simulation

compile:
	
	$(GHDL_CMD) -i $(GHDL_FLAGS) --workdir=simulation --work=work $(TESTBENCHES) $(FILES)
	$(GHDL_CMD) -m  $(GHDL_FLAGS) --workdir=simulation --work=work $(TESTBENCH)

run :
	@cd $(SIMDIR)
	$(GHDL_CMD) -r $(SIMDIR)/$(TESTBENCH) $(GHDL_SIM_OPT) 
	@cd ..
		 
view :
		gunzip --stdout $(SIMDIR)/$(TESTBENCH).vcdgz | $(WAVEFORM_VIEWER) --vcd                                               
		 
clean :
		$(GHDL_CMD) --clean --workdir=simulation
